package com.edu.web;

import com.edu.entity.User;
import com.edu.service.Impl.UserServiceImpl;
import com.edu.service.UserService;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.List;

@WebServlet("/LogServlet")
public class LogServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        UserService userservice=new UserServiceImpl();
        request.setCharacterEncoding("utf-8");
        String getName= request.getParameter("userName");
        String getPass= request.getParameter("passWord");

        if (getName!=null || getPass!=null) {
            List<User> list=userservice.queryUser(getName, getPass);
            System.out.println("list:"+list);
            if (list.size()>0) {
                request.getRequestDispatcher("ShowBookServlet").forward(request,response);
            }
        }else{
            response.sendRedirect("log.jsp");
        }


    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
